local Msg =require("core.Msg")
local OfflinePkDefine = require("offlinepk.Define")
local OfflinePkLogic  = require("offlinepk.OfflinePkLogicW")

local RoleFFI         = require("role.RoleFFI")
function CG_OFFLINE_PK_QUERY(human)
    if human.db.lv < OfflinePkDefine.OPEN_OFFLINE_PK_LV then
        return
    end
    if human.db.offlinePkRank < 1 then
        OfflinePkLogic.checkOfflinePkRank(human)
    end
    OfflinePkLogic.sendSelfPkInfo(human)
    OfflinePkLogic.sendPkPlayerList(human)    
end

function CG_OFFLINE_PK_PLAYER(human)
    if human.db.lv < OfflinePkDefine.OPEN_OFFLINE_PK_LV then
        return
    end
    if human.db.offlinePkRank < 1 then
        OfflinePkLogic.checkOfflinePkRank(human)
    end
    OfflinePkLogic.sendPkPlayerList(human)
end

function CG_OFFLINE_PK_RANK_QUERY(human)
    if human.db.offlinePkRank < 1 then
        OfflinePkLogic.checkOfflinePkRank(human)
    end
    local msg = Msg.gc.GC_OFFLINE_PK_RANK_QUERY
    msg.myRank = human.db.offlinePkRank
    local len = 0
    for i = 1, 100 do
         local node = msg.list[i]
         local data = OfflinePkLogic.TOP_RANK_LIST[i]
         node.uuid = data.uuid
         node.name = data.name
         node.zhandouli = data.zhandouli
         node.lv = data.lv
         len = len + 1     
    end
    msg.list[0] = len
    Msg.send(msg, human.fd)
end

function CG_OFFLINE_PK_LOG(human)
    local mm = Msg.gc.GC_OFFLINE_PK_LOG
    local len = 0
    for i = human.db.offlinePkLogsLen-1, 0, -1 do
        len = len + 1
        local info = mm.list[len]
        local data = human.db.offlinePkLogs[i]
        info.name = RoleFFI.ffi_string(data.name)
        info.win  = data.win
        info.rank = data.rank
        info.time = data.time
        info.result = data.result
        info.active = data.active
    end
    mm.list[0] = len
    Msg.send(mm, human.fd)
end
